class Solution:
    def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:
        
        # 根左右
        if not preorder:
            return None
        
        # 新建根节点
        root = TreeNode(preorder[0])

        # root在中序遍历中的索引
        loc = inorder.index(root.val)

        

        # 开始递归
        root.left = self.buildTree(preorder[1 : loc + 1], inorder[ : loc])
        root.right = self.buildTree(preorder[loc+1 : ], inorder[loc+1: ])

        return root